#include "Graduate.h"
using namespace std;
Graduate::Graduate(int id, string name, string skill, string teacher)
             : Student(id, name), m_skill(skill),m_teacher(teacher){}

Graduate::Graduate() = default;

string Graduate::getTeacher() const {return m_teacher;}

string Graduate::getSkill() const {return m_skill;}

void Graduate::reflect()  {
    Student::reflect();
    cout << "skill:" << m_skill;
    cout << "  teacher: " << m_teacher ;
    cout<< " 研究生学生"<<endl;
}

string Graduate::serialize() {
    return "Id: " + to_string(getId()) + ", Name: " + getName() +
           ", Skill: " +m_skill+ ", Teacher: " + m_teacher;
}

void Graduate::deserialize(const string &info)  {

    size_t pos1 = info.find("Id: ");
    size_t pos2 = info.find(", Name: ");
    size_t pos3 = info.find(", Skill: ");
    size_t pos4 = info.find(", Teacher: ");

    if (pos1 != string::npos && pos2 != string::npos && pos3 != string::npos) {
        int id = stoi(info.substr(pos1 + 4, pos2 - pos1 - 4));
        string name = info.substr(pos2 + 8, pos3 - pos2 - 8);
        string skill = info.substr(pos3 + 9, pos4 - pos3 - 9);
        string teacher = info.substr(pos4 + 10);
        setId(id);
        setName(name);
        this->m_skill = skill;
        this->m_teacher = teacher;
    }
}

istream & Graduate::readFrom(istream &in) {
    cout << "Input id:" << endl;
    in >> m_id;
    cout << "Input name:" << endl;
    in >> m_name;
    cout << "Input skill:" << endl;
    in >> m_skill;
    cout << "Input teacher:" << endl;
    in >> m_teacher;
    return in;
}

Graduate::~Graduate(){}


ostream& operator<<(ostream& out, Graduate& stu) {
    out << "Id: " << stu.getId() << ", Name: " << stu.getName()<< ", Skill: " << stu.m_skill << ", Teacher: " << stu.m_teacher;
    return out;
}


